<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVCWeb.Models.DocCategory>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Index of Category</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script language="javascript" type="text/javascript">
     function ChangeStatus(id, name, status) {
         var s = 'active';
         if (status.toString() == "True") {
             s = 'deactive';
         }
         if (confirm("Are you sure that this category: " + name + " will be " + s + "?")) {
             // Perform change status.
             var action = '<%= Url.Action("ChangeStatus", "DocCategory") %>/' + id;
             var request = new Sys.Net.WebRequest();
             request.set_httpVerb("POST");
             request.set_url(action);
             request.add_completed(ChangeStatusCompleted);
             request.invoke();
         }
     }

     function ChangeStatusCompleted() {
         // Reload page  
         window.location.reload();
     }    
    </script>


    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
    <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <br />
    <h2>
        Index of Category</h2>
    <table cellpadding="4" cellspacing="1" border="0" width="100%" class="DataTable">
    <tr>
    <th>
        Category name
    </th>
    <th>Action</th>
    </tr>
        <% foreach (var item in Model)
           { %>
        <tr>
            <td>
                <%= item.Category%>
            </td>
            <td style="width:1%; white-space:nowrap">
                <%= Html.ActionLink("Edit", "Edit", new { id=item.DocCategoryId }) %> | 
                 <a onclick="ChangeStatus(<%=item.DocCategoryId%>, '<%=item.Category%>', '<%=item.Active%>')" href="JavaScript:void(0)">
                    <%
                        if (item.Active)
                        {
                    %>
                    Active
                    <%
                        }
                    else
                    {%>
                    Deactive
                    <%
                    }%>
                    </a>
            </td>
        </tr>
        <% } %>
    </table>
    <p>
        <%= Html.ActionLink("Create new category", "Create") %>
    </p>
</asp:Content>
